#include "qtstudio.h"
#include "ui_qtstudio.h"
#include <QPushButton>
#include <QGridLayout>
#include <QDebug>
#include <QDialog>
#include "model.h"
#include "mylayout.h"

// 教程1：诺谦 https://blog.csdn.net/qq_37997682/category_11280259_2.html 公众号，Qt教程


QtStudio::QtStudio(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::QtStudio)
{
    ui->setupUi(this);
    //按钮1 非模态弹窗
    QPushButton* btn1 = new QPushButton("非模态弹窗", this);
    connect(btn1, &QPushButton::clicked, this, [=](){
        // 不能指定model的父类为this，不然model始终在大窗口内
        Model* obj = new Model();
        obj->resize(300, 300);
        //接收信号发送者
        QPushButton* send = (QPushButton*)this->sender();
        obj->setWindowTitle(send->text());
        obj->show();
    });
    //按钮2 模态弹窗
    QPushButton* btn2 = new QPushButton("模态弹窗", this);
    connect(btn2, &QPushButton::clicked, this, [=](){
        //测试发现，QWidget是没有exec的，这是QDialog的东西
        QDialog * obj = new QDialog(this);
        obj->resize(300, 300);
        QPushButton* send = (QPushButton*)this->sender();
        obj->setWindowTitle(send->text());
        obj->exec();
    });
    //按钮3 布局管理
    QPushButton* btn3 = new QPushButton("布局管理", this);
    connect(btn3, &QPushButton::clicked, this, [=](){
        Mylayout * obj = new Mylayout();
        obj->resize(300, 300);
        QPushButton* send = (QPushButton*)this->sender();
        obj->setWindowTitle(send->text());
        obj->show();
    });

    //布局
    QGridLayout* grid = new QGridLayout(this);
    grid->addWidget(btn1,0,0);
    grid->addWidget(btn2,0,1);
    grid->addWidget(btn3,0,2);
    grid->setRowStretch(2, 1);
    grid->setColumnStretch(3, 1);

    //基本窗体
    this->setLayout(grid);


}

QtStudio::~QtStudio()
{
    delete ui;
}

